<?
ignore_user_abort(false);

require("config/config.php");
require("lib/lib.mysql.php");
require("lib/lib.common.php");
require("lib/lib.htdb.php");

$db = new db;
$db->connect($db_host, $db_user, $db_pass, $db_name);

$food_id = $_REQUEST["food_id"];
$htdb = new htdb;
$food = $htdb->view_food($food_id, $db);
$gmwt1 = $food["gmwt1"];
$gmwt2 = $food["gmwt2"];
$food_id = $food["food_id"];
$cat_id = $food["cat_id"];
$food_name = $food["food_name"];
$gmwt_desc1 = $food["gmwt_desc1"];
$gmwt_desc2 = $food["gmwt_desc2"];
$gmwt_desc = $food["gmwt_desc1"];

$calories = $food["calories"];
if(!empty($calories)){ $calc_calories = round($calories*$gmwt1/100); }
$saturated_fat = $food["saturated_fat"];
if(!empty($saturated_fat)){ $calc_saturated_fat = round($saturated_fat*$gmwt1/100); }
$trans_fat = $food["trans_fat"];
if(!empty($trans_fat)){ $calc_trans_fat = round($trans_fat*$gmwt1/100); }
$calc_total_fat = ($calc_trans_fat+$calc_saturated_fat);
$carbohydrates = $food["carbohydrates"];
if(!empty($carbohydrates)){ $calc_carbohydrates = round($carbohydrates*$gmwt1/100); }
$dietary_fiber = $food["dietary_fiber"];
if(!empty($dietary_fiber)){ $calc_dietary_fiber = round($dietary_fiber*$gmwt1/100); }
$sugar = $food["sugar"];
if(!empty($sugar)){ $calc_sugar = round($sugar*$gmwt1/100); }
$protein = $food["protein"];
if(!empty($protein)){ $calc_protein = round($protein*$gmwt1/100); }
$cholesterol = $food["cholesterol"];
if(!empty($cholesterol)){ $calc_cholesterol = round($cholesterol*$gmwt1/100); }
$sodium = $food["sodium"];
if(!empty($sodium)){ $calc_sodium = round($sodium*$gmwt1/100); }
$iron = $food["iron"];
if(!empty($iron)){ $calc_iron = round($iron*$gmwt1/100); }
$vitc = $food["vitc"];
if(!empty($vitc)){ $calc_vitc = round($vitc*$gmwt1/100); }
$vitb6 = $food["vitb6"];
if(!empty($vitb6)){ $calc_vitb6 = round($vitb6*$gmwt1/100); }
$calcium = $food["calcium"];
if(!empty($calcium)){ $calc_calcium = round($calcium*$gmwt1/100); }
$vita_ui = $food["vita_ui"];
if(!empty($vita_ui)){ $calc_vita_ui = round($vita_ui*$gmwt1/100); }

ob_start();
require("templates/view_food.htm");
$output = ob_get_contents();
ob_end_clean();

print $output;

$db->close();
?>